package com.zhaoyizhe.demo.model;

import com.zhaoyizhe.demo.enums.ResultCodeEnum;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@Data
public class Result<T> {
    private ResultCodeEnum code;
    // 状态码 200 -1 -2
    private String errorMassage;
    // 数据
    private T data;

    public static <T> Result<T> userNoLogin() {
        // 用户未登录
        Result result = new Result<>();
        result.setCode(ResultCodeEnum.NOLOGIN);
        result.setErrorMassage(ResultCodeEnum.NOLOGIN.getName());
        log.warn("用户未登录");
        return result;
    }

    public static <T> Result<T> succeed(T data) {
        Result result = new Result<>();
        result.setData(data);
        result.setCode(ResultCodeEnum.SUCCEED);
        return result;
    }

    public static <T> Result<T> fail(String msg) {
        Result result = new Result<>();
        result.setData(null);
        result.setErrorMassage(msg);
        result.setCode(ResultCodeEnum.FAIL);
        return result;
    }

}
